﻿var sAgent = navigator.userAgent.toLowerCase();
var IsIE = sAgent.indexOf("msie") != -1;
function $(_sId) { return document.getElementById(_sId) }
String.prototype.trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
function read_radio(rname) {
    var temp = document.getElementsByName(rname);
    for (i = 0; i < temp.length; i++) {
        if (temp[i].checked) {
            return temp[i].value;
        }
    }
}
function read_checkbox(rname) {
    var str = ''
    var temp = document.getElementsByName(rname);
    for (i = 0; i < temp.length; i++) {
        if (temp[i].checked) {
            if (str == '') { str = temp[i].value } else { str = str + ',' + temp[i].value }
        }
    }
    
    return str;
}

function set_radio(rname,val) {
    var temp = document.getElementsByName(rname);
    for (i = 0; i < temp.length; i++) {
        if (temp[i].value==val) {
            temp[i].checked = true;
            return;
        }
    }
}

var numCheck = function (str) {
    var strFormat = "0123456789,";
    for (var i = 0; i < str.length; i++) {
        if (strFormat.indexOf(str.substr(i, 1)) == -1) {
            return false;
        }
    }
    return true;
}


function copyclip(meintext, msg) {
    if (msg == "") { msg = "复制成功！" }
    if (window.clipboardData) {
        if (window.clipboardData.setData("Text", meintext)) {
            alert(msg);
            return true;
        }
        else {
            alert('复制地址失败\n');
            return false;
        }
    } else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
            return false;
        }

        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
				 .createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return false;


        var trans = Components.classes['@mozilla.org/widget/transferable;1']
				  .createInstance(Components.interfaces.nsITransferable);
        if (!trans) return false;

        trans.addDataFlavor('text/unicode');

        var str = new Object();
        var len = new Object();

        var str = Components.classes["@mozilla.org/supports-string;1"]
				.createInstance(Components.interfaces.nsISupportsString);

        var copytext = meintext;

        str.data = copytext;

        trans.setTransferData("text/unicode", str, copytext.length * 2);

        var clipid = Components.interfaces.nsIClipboard;

        if (!clip) return false;

        clip.setData(trans, null, clipid.kGlobalClipboard);

    }
    alert(msg);
    return true;
}



function openScript(url, width, height) {
    if (IsIE) {
        //showModalDialog;
        //showModelessDialog
        var Win = showModalDialog(url, "openScript", 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;dialogLeft:300px;dialogTop:100px;center:yes;help:yes;resizable:no;status:yes;scroll:yes')
    }
    else {
        var Win = window.open(url, "openScript", 'width=' + width + ',height=' + height + ',top=100,left=300,toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no,status=yes');
        Win.focus();
    }
    return;
}

function chkdiv(divid) {
    var chkid = document.getElementById(divid);
    if (chkid != null) { return true; }
    else { return false; }
}

function getpara() {
    var str, parastr
    str = window.location.search;
    parastr = str.substring(1);
    return parastr;
}

function geta() {
    var s = '';
    var url = window.location.search;
    if (url.indexOf("?") != -1) {
        var str = url.substr(1)
        strs = str.split("&");
        for (i = 0; i < strs.length; i++) {
            if ([strs[i].split("=")[0]] == 's') s = unescape(strs[i].split("=")[1]);
        }
        return s;
    }
}

function gets(key) {
    var s = '';
    var url = window.location.search;
    if (url.indexOf("?") != -1) {
        var str = url.substr(1)
        strs = str.split("&");
        for (i = 0; i < strs.length; i++) {
            if ([strs[i].split("=")[0]] == key)
                s = DecodeURI(strs[i].split("=")[1], false);
        }
        return s;
    }
}


function dialog(appurl) {
    appurl = "/";
    var width = 320;
    var height = 180;
    var src = "";
    var path = appurl + "images/dialog/";
    var ShadowWidth = 5;
    //alert(path);
    var sFunc = '<input id="dialogOk" type="button" style="font-size:12px;width:70px;height:26px;line-height:20px;" value=" 确认 " onclick="new dialog(\'' + appurl + '\').reset(1);" /> <input id="dialogCancel" type="button" style="font-size:12px;width:70px;height:26px;line-height:20px;" value=" 取消 " onclick="new dialog(\'' + appurl + '\').reset(0);" />';
    var sClose = '<span id="dialogBoxClose" onclick="new dialog(\'' + appurl + '\').reset(0);" style="color: #666666; cursor:pointer;font-size:16px;">×</span>';
    var sBody = '\
		<table id="dialogBodyBox" border="0" align="center" cellpadding="0" cellspacing="0" width="100%" height="100%" >\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
			<tr>\
				<td width="10"></td>\
				<td align="center" valign="middle" id="ob_boxface"><img id="dialogBoxFace" valign="absmiddle" /></td>\
				<td id="dialogMsg" valign="middle" style="font-size:12px;color:#000;"></td>\
				<td width="10"></td>\
			</tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
			<tr><td id="dialogFunc" colspan="4" align="center">' + sFunc + '</td></tr>\
			<tr height="10"><td colspan="4" align="center"></td></tr>\
		</table>\
	';
    var sBox = '\
		<table id="dialogBox" width="' + width + '" border="0" cellpadding="0" cellspacing="0" style="border:1px solid #b5b7bf;display: none; z-index: 1000; ">\
			<tr height="30" bgcolor="#eceff3" >\
				<td>\
					<table onselectstart="return false;" style="-moz-user-select:none;" width="100%" border="0" cellpadding="0" cellspacing="0">\
						<tr>\
							<td width="12" ></td>\
							<td id="dialogBoxTitle" onmousedown="new dialog().moveStart(event, \'dialogBox\')" style="color:#666666;cursor:move;font-size:12px;font-weight:bold;">提示信息</td>\
							<td id="dialogClose" width="27" align="right" valign="middle" >\
								' + sClose + '\
							</td>\
							<td width="12"></td>\
						</tr>\
					</table>\
				</td>\
			</tr>\
			<tr id="dialogHeight" height="' + height + '">\
				<td id="dialogBody" style="background:#fff;color:#000;">' + sBody + '</td>\
			</tr>\
		</table>\
		<div id="dialogBoxShadow"></div>\
		<iframe id="dialogBoxDivShim" scrolling="no" frameborder="0" style="position: absolute; top: 0px; left: 0px; display: none; ">\
	';
    this.show = function () { document.getElementById('dialogBodyBox') ? function () { } : this.init(); this.middle('dialogBox'); this.shadow(); }
    this.reset = function (_int) {
        if (_int == 1 && document.getElementById('dialogBoxTitle').innerHTML != "提示信息") {
            return;
        }
        document.getElementById('dialogBox').style.display = 'none';
        document.getElementById('dialogBoxShadow').style.display = "none";
        document.getElementById('dialogBoxDivShim').style.display = "none";
        document.getElementById('dialogBody').innerHTML = sBody;
        document.getElementById("cover_div").style.display = 'none';

    }
    this.html = function (_sHtml) { document.getElementById("dialogBody").innerHTML = _sHtml; this.show(); }
    this.init = function () {
        popCoverDiv();
        document.getElementById('dialogCase') ? document.getElementById('dialogCase').parentNode.removeChild(document.getElementById('dialogCase')) : function () { };
        var oDiv = document.createElement('span');
        oDiv.id = "dialogCase";
        oDiv.innerHTML = sBox;
        document.body.appendChild(oDiv);
        
    }
    this.button = function (_sId, _sFuc) {
        if (document.getElementById(_sId)) {
            document.getElementById(_sId).style.display = '';
            if (document.getElementById(_sId).addEventListener) {
                if (document.getElementById(_sId).act) { document.getElementById(_sId).removeEventListener('click', function () { eval(document.getElementById(_sId).act) }, false); }
                document.getElementById(_sId).act = _sFuc;
                document.getElementById(_sId).addEventListener('click', function () { eval(_sFuc) }, false);
            } else {
                if (document.getElementById(_sId).act) { document.getElementById(_sId).detachEvent('onclick', function () { eval(document.getElementById(_sId).act) }); }
                document.getElementById(_sId).act = _sFuc;
                document.getElementById(_sId).attachEvent('onclick', function () { eval(_sFuc) });
            }
        }
    }
    this.shadow = function () {


        var oShadow = document.getElementById('dialogBoxShadow');
        var oDialog = document.getElementById('dialogBox');
        var IfrRef = document.getElementById('dialogBoxDivShim');
        oShadow.style.position = "absolute";
        oShadow.style.background = "#000";
        oShadow.style.display = "block";
        if (IsIE) {
            oShadow.style.filter = "Alpha(Opacity=10)";
            oShadow.style.opacity = "0.1";
        } else {
            oShadow.style.opacity = "0.1";
        }
        oShadow.style.top = oDialog.offsetTop + ShadowWidth + "px";
        oShadow.style.left = oDialog.offsetLeft + ShadowWidth + "px";
        oShadow.style.width = oDialog.offsetWidth + "px";
        oShadow.style.height = oDialog.offsetHeight + "px";
        oShadow.style.zIndex = oDialog.style.zIndex - 1;


        IfrRef.style.background = "#000";
        
        IfrRef.style.filter = "alpha(opacity=10)";
        IfrRef.style.opacity = "0.1";
        IfrRef.style.top = oDialog.offsetTop + ShadowWidth + "px";
        IfrRef.style.left = oDialog.offsetLeft + ShadowWidth + "px";
        IfrRef.style.width = oDialog.offsetWidth + "px";
        IfrRef.style.height = oDialog.offsetHeight + "px";
        IfrRef.style.zIndex = oDialog.style.zIndex - 2;
        if (IsIE) {
            IfrRef.style.display = "block";
        }
        else {
            IfrRef.style.display = "none";
        }
        
    }
    this.open = function (_sUrl, _sMode) {
        
        this.show();
        if (!_sMode || _sMode == "no" || _sMode == "yes" ) {
            document.getElementById("dialogBody").innerHTML = "<iframe id='dialogFrame' width='100%' height='100%' frameborder='0' scrolling='" + _sMode + "'></iframe>";
            document.getElementById("dialogFrame").src = _sUrl;
        }
    }
    this.event = function (_sMsg, _sOk, _sCancel, _sClose) {
        document.getElementById('dialogFunc').innerHTML = sFunc;
        document.getElementById('dialogClose').innerHTML = sClose;
        document.getElementById('dialogBodyBox') == null ? document.getElementById('dialogBody').innerHTML = sBody : function () { };
        document.getElementById('dialogMsg') ? document.getElementById('dialogMsg').innerHTML = _sMsg : function () { };
        this.show();
        _sOk ? this.button('dialogOk', _sOk) | document.getElementById('dialogOk').focus() : document.getElementById('dialogOk').style.display = 'none';
        _sCancel ? this.button('dialogCancel', _sCancel) : document.getElementById('dialogCancel').style.display = 'none';
        _sClose ? this.button('dialogBoxClose', _sClose) : function () { };
        //_sOk ? this.button('dialogOk', _sOk) : _sOk == "" ? function(){} : document.getElementById('dialogOk').style.display = 'none';
        //_sCancel ? this.button('dialogCancel', _sCancel) : _sCancel == "" ? function(){} : document.getElementById('dialogCancel').style.display = 'none';
    }
    this.set = function (_oAttr, _sVal) {
        var oShadow = document.getElementById('dialogBoxShadow');
        var oDialog = document.getElementById('dialogBox');
        var oHeight = document.getElementById('dialogHeight');

        if (_sVal != '') {
            switch (_oAttr) {
                case 'title':
                    document.getElementById('dialogBoxTitle').innerHTML = _sVal;
                    //title = _sVal;
                    break;
                case 'width':
                    oDialog.style.width = _sVal + "px";
                    width = _sVal;
                    break;
                case 'height':
                    oHeight.style.height = _sVal + "px";
                    height = _sVal;
                    break;
                case 'src':
                    if (parseInt(_sVal) >= 0) {
                        document.getElementById('dialogBoxFace') ? document.getElementById('dialogBoxFace').src = path + _sVal + '.png' : function () { };
                    } else {
                        document.getElementById('dialogBoxFace') ? document.getElementById('dialogBoxFace').src = _sVal : function () { };
                    }
                    src = _sVal;
                    break;
                case "html":
                    document.getElementById("ob_boxface").innerHTML = "";
                    document.getElementById("dialogMsg").innerHTML = _sVal;
                    break;
                case "nobtn":
                    document.getElementById("dialogFunc").style.display = "none";
                    break;
            }
        }
        this.middle('dialogBox');
        oShadow.style.top = oDialog.offsetTop + ShadowWidth + "px";
        oShadow.style.left = oDialog.offsetLeft + ShadowWidth + "px";
        oShadow.style.width = oDialog.offsetWidth + "px";
        oShadow.style.height = oDialog.offsetHeight + "px";
    }
    this.moveStart = function (event, _sId) {
        var oObj = document.getElementById(_sId);
        oObj.onmousemove = mousemove;
        oObj.onmouseup = mouseup;
        oObj.setCapture ? oObj.setCapture() : function () { };
        oEvent = window.event ? window.event : event;
        var dragData = { x: oEvent.clientX, y: oEvent.clientY };
        var backData = { x: parseInt(oObj.style.top), y: parseInt(oObj.style.left) };
        function mousemove() {
            var oEvent = window.event ? window.event : event;
            var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
            var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
            oObj.style.left = iLeft + "px";
            oObj.style.top = iTop + "px";
            document.getElementById('dialogBoxShadow').style.left = iLeft + ShadowWidth + "px";
            document.getElementById('dialogBoxShadow').style.top = iTop + ShadowWidth + "px";

            document.getElementById('dialogBoxDivShim').style.left = iLeft + "px";
            document.getElementById('dialogBoxDivShim').style.top = iTop + "px";

            dragData = { x: oEvent.clientX, y: oEvent.clientY };


        }
        function mouseup() {
            var oEvent = window.event ? window.event : event;
            oObj.onmousemove = null;
            oObj.onmouseup = null;
            if (oEvent.clientX < 1 || oEvent.clientY < 1 || oEvent.clientX > document.body.clientWidth || oEvent.clientY > document.body.clientHeight) {
                oObj.style.left = backData.y + "px";
                oObj.style.top = backData.x + "px";
                document.getElementById('dialogBoxShadow').style.left = backData.y + ShadowWidth + "px";
                document.getElementById('dialogBoxShadow').style.top = backData.x + ShadowWidth + "px";

                document.getElementById('dialogBoxDivShim').style.left = backData.y + "px";
                document.getElementById('dialogBoxDivShim').style.top = backData.x + "px";
            }
            oObj.releaseCapture ? oObj.releaseCapture() : function () { };
        }
    }
    this.middle = function (_sId) {
        var theWidth;
        var theHeight;
        if (document.documentElement && document.documentElement.clientWidth) {
            theWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft * 2; ;
            theHeight = document.documentElement.clientHeight + document.documentElement.scrollTop * 2; ;
        } else if (document.body) {
            theWidth = document.body.clientWidth;
            theHeight = document.body.clientHeight;
        } else if (window.innerWidth) {
            theWidth = window.innerWidth;
            theHeight = window.innerHeight;
        }
        document.getElementById(_sId).style.display = '';
        document.getElementById(_sId).style.position = "absolute";
        document.getElementById(_sId).style.left = (theWidth / 2) - (document.getElementById(_sId).offsetWidth / 2) + "px";
        //alert(in_ob_useradmin);
        if (document.all || document.getElementById("user_page_top")) {
            //document.getElementById(_sId).style.top = (theHeight / 2 + document.body.scrollTop) - (document.getElementById(_sId).offsetHeight / 2) - 120 + "px";
            var sTop = (theHeight / 2 + document.body.scrollTop) - (document.getElementById(_sId).offsetHeight / 2) - 20;
            if (sTop < 0) {
                sTop = 5;
            }
            document.getElementById(_sId).style.top = sTop + "px";
        } else {
            var sClientHeight = parent ? parent.document.body.clientHeight : document.body.clientHeight;
            var sScrollTop = parent ? parent.document.body.scrollTop : document.body.scrollTop;
            //var sTop = -80 + (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2);
            //document.getElementById(_sId).style.top = sTop > 0 ? sTop : (sClientHeight / 2 + sScrollTop) - (document.getElementById(_sId).offsetHeight / 2)+"px";
            var sTop = (theHeight / 2 + document.body.scrollTop) - (document.getElementById(_sId).offsetHeight / 2) - 20;
            if (sTop < 0) {
                sTop = 5;
            }
            document.getElementById(_sId).style.top = sTop + "px";
        }
    }

}


function oAjax(url, callback) {
    try {
        this.HttpRequest = null;
        this.Debug = false;
        this.Url = url;
        this.ContentType = "text/xml";
        this.HttpRequest = this.createXMLHttpRequest();

        if (this.HttpRequest == null) {
            this._debug("XMLHttpRequest create failure!");
            return;
        }

        var xhReq = this.HttpRequest;
        xhReq.onreadystatechange = function () {
            oAjax._OnReadyStateChange(xhReq, callback);
        }

    } catch (e) {
        this._debug("unknow err: " + e.message);
    }
}

/*
* Get URL resource
*/
oAjax.prototype.Get = function () {

    this.SetContentType("text/html");
    this._get();
}

/*
* Post data to the server
*/
oAjax.prototype.Post = function (arrKey, arrValue) {
    var data = '';
    var i;
    this.SetContentType("application/x-www-form-urlencoded'");
    for (i = 0; i < arrKey.length; i++) {
        data += "&" + escape(arrKey[i]) + "=" + encodeURIComponent(URLencode(arrValue[i]));
        //alert(URLencode(arrValue[i]));
        //data += "&" + arrKey[i] + "=" + arrValue[i];
    }
    //document.write(data);
    data = data.replace(/^&/g, "");
    this._post(data);
}

/*
* Initialization for oAjax class
*/
oAjax.prototype.Init = function () {
    // initialization
}

/*
* Change URL for Request
*/
oAjax.prototype.SetUrl = function (url) {
    this.Url = url;
}

/*
* Set content type for HTTP header before sending Request
*/
oAjax.prototype.SetContentType = function (type) {
    this.ContentType = type;
}

oAjax.prototype.createXMLHttpRequest = function () {

    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
    try { return new XMLHttpRequest(); } catch (e) { }
    return null;
}

/*
* Debug information for testing
*/
oAjax.prototype._debug = function (message) {

    if (this.Debug) {
        alert(message);
    }
}

/*
* Process message and data from server
*/
oAjax._OnReadyStateChange = function (xreq, callback) {

    if (xreq == null) {
        return;
    }

    /*Status is completed, then process result */
    if (xreq.readyState == 4) {
        // OK        
        if (xreq.status == 200) {
            //			alert(xreq.responseText);
            callback(this.ArrayValue(xreq.responseXML));
        } else {
            //			alert('服务器端错误！');
            document.write(xreq.responseText);
        }
    } else {
        // Others
    }
}

oAjax.prototype._SendRequest = function (HttpMethod, data) {

    this._debug('Send Request ' + HttpMethod + data);

    if (this.HttpRequest != null) {
        this.HttpRequest.open(HttpMethod, this.Url, true);

        if (this.ContentType != null) {
            //  <FORM> MIME type: application/x-www-form-urlencoded
            this.HttpRequest.setRequestHeader("Content-Type", this.ContentType);
        }
        this.HttpRequest.send(data);
        return true;
    }
    return false;
}

/* Send GET Request to server */
oAjax.prototype._get = function () {

    this._debug('GET');
    return this._SendRequest("GET", null);
}

/* Send POST Request and data to server */
oAjax.prototype._post = function (data) {

    this._debug('POST');
    return this._SendRequest("POST", data);
}

oAjax.ArrayValue = function (xmlobj) {
    var array = new Array();
    var i = 0;
    var response = xmlobj.getElementsByTagName('Response')[0];
    var element = response.firstChild;
    array[i] = element.firstChild.nodeValue;
    while (element = element.nextSibling) {
        i++;
        array[i] = element.firstChild.nodeValue;
    }
    return array;
}

var EncodeURI = function (unzipStr, isCusEncode) {
    if (isCusEncode) {
        var zipArray = new Array();
        var zipstr = "";
        var lens = new Array();
        for (var i = 0; i < unzipStr.length; i++) {
            var ac = unzipStr.charCodeAt(i);
            zipstr += ac;
            lens = lens.concat(ac.toString().length);
        }
        zipArray = zipArray.concat(zipstr);
        zipArray = zipArray.concat(lens.join("O"));
        return zipArray.join("N");
    } else {
        //return encodeURI(unzipStr);
        var zipstr = "";
        var strSpecial = "!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
        var tt = "";

        for (var i = 0; i < unzipStr.length; i++) {
            var chr = unzipStr.charAt(i);
            var c = StringToAscii(chr);
            tt += chr + ":" + c + "n";
            if (parseInt("0x" + c) > 0x7f) {
                zipstr += encodeURI(unzipStr.substr(i, 1));
            } else {
                if (chr == " ")
                    zipstr += "+";
                else if (strSpecial.indexOf(chr) != -1)
                    zipstr += "%" + c.toString(16);
                else
                    zipstr += chr;
            }
        }
        return zipstr;
    }
}

var DecodeURI = function (zipStr, isCusEncode) {
    if (isCusEncode) {
        var zipArray = zipStr.split("N");
        var zipSrcStr = zipArray[0];
        var zipLens;
        if (zipArray[1]) {
            zipLens = zipArray[1].split("O");
        } else {
            zipLens.length = 0;
        }

        var uzipStr = "";

        for (var j = 0; j < zipLens.length; j++) {
            var charLen = parseInt(zipLens[j]);
            uzipStr += String.fromCharCode(zipSrcStr.substr(0, charLen));
            zipSrcStr = zipSrcStr.slice(charLen, zipSrcStr.length);
        }
        return uzipStr;
    } else {
        //return decodeURI(zipStr);
        var uzipStr = "";

        for (var i = 0; i < zipStr.length; i++) {
            var chr = zipStr.charAt(i);
            if (chr == "+") {
                uzipStr += " ";
            } else if (chr == "%") {
                var asc = zipStr.substring(i + 1, i + 3);
                if (parseInt("0x" + asc) > 0x7f) {
                    uzipStr += decodeURI("%" + asc.toString() + zipStr.substring(i + 3, i + 9).toString()); ;
                    i += 8;
                } else {
                    uzipStr += AsciiToString(parseInt("0x" + asc));
                    i += 2;
                }
            } else {
                uzipStr += chr;
            }
        }
        return uzipStr;
    }
}

var StringToAscii = function (str) {
    return str.charCodeAt(0).toString(16);
}

var AsciiToString = function (asccode) {
    return String.fromCharCode(asccode);
}


function addjs(url) {
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.src = url;
    oScript.charset = "GB2312";
    oHead.appendChild(oScript);

}

//通用回调函数
function show_return(arrobj) {
    if (arrobj) {
        if (arrobj[1] == "-1") {
            eval(arrobj[2]);
            return;
        }
        var oDialog = new dialog("");
        oDialog.init();
        oDialog.set('src', arrobj[1]);
        oDialog.event(arrobj[0], '');
        oDialog.button('dialogOk', arrobj[2]);
    }
}

function goto(url) {
    if (url != "") {
        window.location = url;
    } else {
        history.back();
    }
    return true;
}

function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie =
		escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

function getCookie(cookieName) {
    var cookieValue = '';
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
        else cookieValue = unescape(document.cookie.substring(posValue));
    }
    return (cookieValue);
}

function getElementsByName_iefix(tag, name) {
    var arr = "";
    var elem = document.getElementsByTagName(tag);
    var arr = new Array();
    for (var i = 0, iarr = 0; i < elem.length; i++) {
        att = elem[i].getAttribute("name");
        if (att == name) {
            arr[iarr] = elem[i];
            iarr++;
        }
    }
    return arr;
}

function RndNum(n) {
    var rnd = "";
    for (var i = 0; i < n; i++)
        rnd += Math.floor(Math.random() * 10);
    return rnd;
}

function apost() {
    var arrKey = new Array();
    var arrValue = new Array();
    var i = 0;
    this.add = function (sid) {
        arrKey[i] = sid;
        var obj = document.getElementById(sid);
        if (!obj) {
            obj = document.getElementsByName(sid);
        }
        if (obj) {
            var t = obj;
            if (obj.length > 0) t = obj[0];
            if (t.type == 'checkbox') {
                arrValue[i] = read_checkbox(sid);
                //alert(sid+"="+read_checkbox(sid));

            } else if (t.type == 'radio') {
                arrValue[i] = read_radio(sid);

            } else {
                if (obj.value) {
                    arrValue[i] = obj.value;
                }
                else {
                    //alert(sid);
                    arrValue[i] = "";
                }
            }
        }
        else {
            
            arrValue[i] = "";
        }
        i++;

    }

    this.send = function (url, cfun) {
        if (cfun == "") {
            cfun = show_return;
        }
        var Ajax = new oAjax(url, cfun);
        Ajax.Post(arrKey, arrValue);
    }
}
function obaddjs(url) {
    
    var oHead = document.getElementsByTagName('HEAD').item(0);
    var oScript = document.createElement("script");
    oScript.type = "text/javascript";
    oScript.src = url;
    oScript.charset = "utf8";
    oHead.appendChild(oScript);

}


function getBodySize() {
    var bodySize = [];
    with (document.documentElement) {
        bodySize[0] = (scrollWidth > clientWidth) ? scrollWidth : clientWidth;
        bodySize[1] = (scrollHeight > clientHeight) ? scrollHeight : clientHeight;
    }
    return bodySize;
}


function popCoverDiv() {
    if (document.getElementById("cover_div")) {
        document.getElementById("cover_div").style.display = '';
    } else {
        var coverDiv = document.createElement('div');
        document.body.appendChild(coverDiv);
        coverDiv.id = 'cover_div';

        with (coverDiv.style) {
            position = 'absolute';
            background = '#999999';
            left = '0px';
            top = '0px';
            var bodySize = getBodySize();
            width = bodySize[0] + 'px'
            height = bodySize[1] + 'px';
            zIndex = 98;
            if (IsIE) {
                filter = "Alpha(Opacity=60)";
                opacity = 0.5;
            } else {
                opacity = 0.5;
            }
        }
    }
}

function URLencode(sStr) {
    return encodeURIComponent(sStr).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27').replace(/\//g, '%2F');
}

function showdiv(divid) {
    if (document.getElementById(divid).style.display == "none") {
        document.getElementById(divid).style.display = "block";
    } else {
        document.getElementById(divid).style.display = "none";
    }
}

/*加入收藏夹*/
function addfavorite(url, title) {
    try {
        window.external.addfavorite(url, title);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(title, url, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用ctrl+d进行添加");
        }
    }
}

function show_croom(ihtml) {
    var oDialog = new dialog("");
    oDialog.init();
    oDialog.set('width', "320");
    oDialog.set('title', "选择管理后台");
    oDialog.set('html', "<div style='padding:20px'>" + ihtml + "</div>");
    oDialog.set('nobtn', 1);
    oDialog.show();
}

function getcodeimg(t) {
    if (document.getElementById("codestr" + t)) {
        document.getElementById("codestr" + t).src = "/code.aspx?s=" + t + "&rnd" + Math.random();
    }
}

function innerHTMLbyOsval(osval,html) {
    obj = getElementsByOsval(document.body, 'div', osval);
    if (obj.length > 0) {
        for (var i = 0, l = obj.length; i < l; i++) {
            obj[i].innerHTML = html;
        }
    }
}

function show_osuinfo(uid, gname, img) {

    var obj = getElementsByOsval(document.body, 'a', 'os_face_' + uid,"osval");
    if (obj.length > 0) {
        for (var i = 0, l = obj.length; i < l; i++) {
            obj[i].innerHTML = "<img src='" + img + "' />"
        }
    }
    obj = getElementsByOsval(document.body, 'span', 'os_gname_' + uid,"osval");
    if (obj.length > 0) {
        for (var i = 0, l = obj.length; i < l; i++) {
            obj[i].innerHTML = "(" + gname + ")";
           
        }
    }
    
}

function getElementsByOsval(oElem, strTagName, strValue,strAttname) {
    var arrElements = (strTagName == '*' && oElem.all) ? oElem.all : oElem.getElementsByTagName(strTagName);
    var returnArrElements = new Array();
    var oRegExp = new RegExp('(^|//s)' + strValue + '($|//s)');
    for (var i = 0; i < arrElements.length; i++) {

        if (oRegExp.test(arrElements[i].getAttribute('osval'))) {
            returnArrElements.push(arrElements[i]);
        }
    }
    return (returnArrElements);
}

function isMobile(value) {
    if (/^13\d{9}$/g.test(value) || (/^15[0-35-9]\d{8}$/g.test(value)) ||
(/^18[05-9]\d{8}$/g.test(value))) {
        return true;
    } else {
        return false;
    }
}

function initUinfo() {    
    var obj = document.getElementsByName("os_getuid");
    var s = ",";
    if (obj.length > 0) {
        for (var i = 0; i < obj.length; i++) {
            if (s.indexOf(',' + obj[i].value + ',')<0) {
                s += obj[i].value + ",";
            }
        }
    }
    obaddjs('/ajax.aspx?action=show_uinfo&uid=' + s);
}

if (IsIE) {
    window.attachEvent("onload", initUinfo);
} else {
    window.addEventListener("load", initUinfo, true);
}

function show_recmt(mid, ahtml) {
    if (document.getElementById('os_recmtdiv' + mid)) {
        document.getElementById('os_recmtdiv' + mid).innerHTML += ahtml;
    }
}